use super::Currency;
use crate::security::forex::Forex;
use crate::util::http::get;

pub(in crate::security::forex) async fn load_forex(
    base_currency: Currency<'_>,
) -> anyhow::Result<Forex> {
    let access_key = "ae8f9aac486406a474eda53cb05fdf93";
    let resp = get(format!(
        "http://data.fixer.io/api/latest?access_key={}&base={}",
        access_key, base_currency
    )
    .as_ref())
    .await?;
    let result = serde_json::from_str(resp.to_str_data().as_str())?;
    Ok(result)
    // match result {
    //     Ok(forex) => Ok(forex),
    //     _ => anyhow::bail!("")
    // }
    //anyhow::bail!("")
}
